//
//  UpLoadViewController.m
//  滴滴快拍
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 dllo. All rights reserved.
//
//  趣拍
//appKey：2082ce01f940f2d
//appSecret：022ad3cd983b46b691b869f0deb3be41重置
//appName：aglqupai1-0
// kQPDomain =  aglqupai1-0.s.qupai.me

// bmob
//Application ID 17391b159f6a1cbbf2bc3111d944d8ea 复制
//REST API Key:40f52576b0dcc8b4bdc3393414c94ab1 复制
//Secret Key:e7f2ccd6803faf97 复制
//Master Key:57105b3e5c8af5f8d566f84f2ee6d27c
#import "UpLoadViewController.h"
#import <ALBBQuPaiPlugin/ALBBQuPaiPlugin.h>
#import <BmobSDK/Bmob.h>
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import "LookViewController.h"
#import "AGLRecordValueView.h"
#import "Header.h"


@interface UpLoadViewController ()

// 录制视频基本设置
@property (nonatomic, strong) AGLRecordValueView *widthView;
@property (nonatomic, strong) AGLRecordValueView *heightView;
@property (nonatomic, strong) AGLRecordValueView *minDurationView;
@property (nonatomic, strong) AGLRecordValueView *maxDurationView;
@property (nonatomic, strong) AGLRecordValueView *bitRateView;



@property (nonatomic, strong) NSMutableArray *taskArray;
@property (nonatomic, strong) UIButton *testButtonClick;
@property (nonatomic, strong) UIButton *upLoadButton;
@property (nonatomic, strong) UIProgressView *processView;


@property (nonatomic, strong) QPUploadTask *task;
@property (nonatomic, strong) UIAlertController *alertView;
@property (nonatomic, strong) NSString *previewStr;
@property (nonatomic, strong) NSString *streambase;


@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
@property (nonatomic, strong) AVAudioSession *avaudioSession;
@property (nonatomic, strong) BaseView *alpaView;

@end

@implementation UpLoadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"录制";
    self.view.backgroundColor = [UIColor whiteColor];
    [self createView];
    [self setupData];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"看视频" style:UIBarButtonItemStylePlain target:self action:@selector(rightBar:)];

    
}

- (void)rightBar:(UIBarButtonItem *)rightBar {
    LookViewController *lookVC = [[LookViewController alloc] init];
    [self.navigationController pushViewController:lookVC animated:YES];
}


- (void)setupData {
    self.taskArray = [NSMutableArray array];
    NSArray *tasks = [[QPUploadTaskManager shared] getAllUploadTasks];
    [self.taskArray addObjectsFromArray:tasks];
}

- (void)createView {
    BaseImageView *backView = [[BaseImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:backView];
    backView.image = [UIImage imageNamed:@"image01.jpg"];
//    [self createVideoPlayerView];
    [self createTextFeild];
   
    
    self.testButtonClick = [UIButton buttonWithType:UIButtonTypeSystem];
    self.testButtonClick.frame = CGRectMake((SCREEN_WIDTH - SCREEN_HEIGHT/10)/2, SCREEN_HEIGHT / 10 * 8 - 35-64-49, SCREEN_HEIGHT/10, SCREEN_HEIGHT / 10);
    [self.testButtonClick setTitle:@"录制" forState:UIControlStateNormal];
    [self.testButtonClick addTarget:self action:@selector(testButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.testButtonClick];
    self.testButtonClick.layer.cornerRadius = SCREEN_HEIGHT/20;
    [self.testButtonClick setBackgroundColor:[UIColor colorWithRed:186 / 256.0 green:33 / 256.0 blue:11 / 256.0 alpha:0.8]];
    [self.testButtonClick setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    
    
    self.upLoadButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.upLoadButton.frame = CGRectMake(0, SCREEN_HEIGHT / 10 * 9-64-49, SCREEN_WIDTH, SCREEN_HEIGHT / 10);
    [self.upLoadButton setTitle:@"上传" forState:UIControlStateNormal];
    [self.upLoadButton addTarget:self action:@selector(upLoadButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.upLoadButton];
    self.upLoadButton.backgroundColor = [UIColor colorWithRed:244/255.0 green:159/255.0 blue:67/255.0 alpha:1];
    [self.upLoadButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.upLoadButton.hidden = YES;
    
    self.processView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    self.processView.frame = CGRectMake(0, SCREEN_HEIGHT/ 10 * 9 - 2-64-49, SCREEN_WIDTH, 2);
    [self.view addSubview:self.processView];
    //设置进度的颜色
    self.processView.progressTintColor = [UIColor colorWithRed:186 / 256.0 green:33 / 256.0 blue:11 / 256.0 alpha:1];
    //设置它的轨道颜色
    self.processView.trackTintColor = [UIColor clearColor];
    
    // 创建alertView
    self.alertView = [UIAlertController alertControllerWithTitle:@"发布" message:@"请输入视频标题" preferredStyle:UIAlertControllerStyleAlert];
    [self.alertView addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"视频标题";
    }];
    
    
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    [self.alertView addAction:cancel];
    
    
    
    UIAlertAction *certain = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"%@", self.alertView.textFields[0].text);
        BmobObject *users = [BmobObject objectWithClassName:@"VideoTable"];
        [users setObject:self.alertView.textFields[0].text forKey:@"ft"];
        [users setObject:self.streambase forKey:@"streambase"];
        [users setObject:self.previewStr forKey:@"previewStr"];
        
        [users saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
            if (!error) {
                NSLog(@"发布成功");
            } else {
                NSLog(@"发布失败");
                UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:nil
                                                                    message:[[error userInfo] objectForKey:@"error"]
                                                                   delegate:nil
                                                          cancelButtonTitle:nil
                                                          otherButtonTitles:@"ok", nil];
                [alertview show];
            }
            
        }];
        
    }];
    [self.alertView addAction:certain];
    
    
    
}

- (void)createTextFeild {
    
    self.minDurationView = [[AGLRecordValueView alloc] initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH - 40, 40)];
    [self.view addSubview:self.minDurationView];
    self.minDurationView.layer.cornerRadius = 10;
    self.minDurationView.layer.masksToBounds = YES;

    self.minDurationView.myLabel.text = @"最小时长";
    self.minDurationView.myTextField.text = @"2";
    self.minDurationView.myTextField.tag = 5300;
    
    self.maxDurationView = [[AGLRecordValueView alloc] initWithFrame:CGRectMake(20, 70, SCREEN_WIDTH - 40, 40)];
    [self.view addSubview:self.maxDurationView];
    self.maxDurationView.layer.cornerRadius = 10;
    self.maxDurationView.layer.masksToBounds = YES;

    self.maxDurationView.myLabel.text = @"最大时长";
    self.maxDurationView.myTextField.text = @"8";
    self.maxDurationView.myTextField.tag = 5301;
    
    
    self.bitRateView = [[AGLRecordValueView alloc] initWithFrame:CGRectMake(20, 120, SCREEN_WIDTH - 40, 40)];
    [self.view addSubview:self.bitRateView];
    self.bitRateView.layer.cornerRadius = 10;
    self.bitRateView.layer.masksToBounds = YES;

    self.bitRateView.myLabel.text = @"码率";
    self.bitRateView.myTextField.text = @"2000000";
    self.bitRateView.myTextField.tag = 5302;
    
        self.widthView = [[AGLRecordValueView alloc] initWithFrame:CGRectMake(20, 170, SCREEN_WIDTH - 40, 40)];
    [self.view addSubview:self.widthView];
    self.widthView.layer.cornerRadius = 10;
    self.widthView.layer.masksToBounds = YES;

    self.widthView.myLabel.text = @"视频宽";
    self.widthView.myTextField.text = @"640";
    self.widthView.myTextField.tag = 5303;
    
    self.heightView = [[AGLRecordValueView alloc] initWithFrame:CGRectMake(20, 220, SCREEN_WIDTH - 40, 40)];
    [self.view addSubview:self.heightView];
    self.heightView.layer.cornerRadius = 10;
    self.heightView.layer.masksToBounds = YES;

    self.heightView.myLabel.text = @"视频高";
    self.heightView.myTextField.text = @"360";
    self.heightView.myTextField.tag = 5304;
    
    
    
}

//- (void)createVideoPlayerView {
//    /**
//     *  设置其他音乐软件播放的音乐不被打断
//     */
//    
//    self.avaudioSession = [AVAudioSession sharedInstance];
//    NSError *error = nil;
//    [self.avaudioSession setCategory:AVAudioSessionCategoryAmbient error:&error];
//    
//    
//    
//    NSString *urlStr = [[NSBundle mainBundle]pathForResource:@"1.mp4" ofType:nil];
//    
//    NSURL *url = [NSURL fileURLWithPath:urlStr];
//    
//    _moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
//    //    _moviePlayer.controlStyle = MPMovieControlStyleDefault;
//    [_moviePlayer play];
//    [_moviePlayer.view setFrame:self.view.bounds];
//    
//    [self.view addSubview:_moviePlayer.view];
//    _moviePlayer.shouldAutoplay = YES;
//    [_moviePlayer setControlStyle:MPMovieControlStyleNone];
//    [_moviePlayer setFullscreen:YES];
//    
//    [_moviePlayer setRepeatMode:MPMovieRepeatModeOne];
//    
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(playbackStateChanged)
//                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
//                                               object:_moviePlayer];
//    
//    
//    self.alpaView = [[BaseView alloc] initWithFrame:self.view.bounds];
//    _alpaView.backgroundColor = [UIColor clearColor];
//    [_moviePlayer.view addSubview:_alpaView];
//
//}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    for (int i = 5300; i <= 5306; i++) {
        UITextField *text = (UITextField *)[self.view viewWithTag:i];
        [text resignFirstResponder];
    }
}


- (void)testButtonClick:(UIButton *)button {
    self.upLoadButton.hidden = YES;
    
    // 1.获取QupaiSDK实例
    QupaiSDK *sdk = [QupaiSDK shared];
    [sdk setDelegte:(id<QupaiSDKDelegate>)self];
    
    // 2.创建视频录制界面控制器
    //在需要弹出视频录界面的制控制器中添加以下代码：
    CGSize videoSize = CGSizeMake([self.widthView.myTextField.text integerValue], [self.heightView.myTextField.text integerValue]);
    UIViewController *recordController = [sdk createRecordViewControllerWithMinDuration:[self.minDurationView.myTextField.text integerValue] maxDuration:[self.maxDurationView.myTextField.text integerValue] bitRate:[self.bitRateView.myTextField.text integerValue] videoSize:videoSize];
    
    [self presentViewController:recordController animated:YES completion:nil];
    
    //    参数说明：
    //    1.mimDuration 允许拍摄的最小时长，时长越大，产生的视频文件越大。
    //    2.maxDuration 允许拍摄的最大时长，时长越大，产生的视频文件越大。
    //    3.bitRate 视频码率，建议600☓1000-2000☓1000,码率越大，视频越清析，视频文件也会越大。参考：8秒的视频以2000☓1000的码率压缩，文件大小1.5M-2M。请开发者根据自己的业务场景设置时长和码率。
    
    
    
    
    // 3.个性化设置（可选）
    //    目前可选设置有以下10个参数，根据自己的业务需求选用：
    //    1) 首帧图图片质量，压缩质量可设置的值为0-1，代码如下：
    
    sdk.thumbnailCompressionQuality = 0.8;
    //    2) 语言本地化配置文件url,代码如下：
    
//    sdk.localizableFileUrl = [[NSBundle mainBundle] URLForResource:@"QPLocalizable_en" withExtension:@"plist"];
    //    英文语言plist文件参考如下，其它语言可自行添加：
    
    //    3) 是否显示拍摄时长，代码如下：
    
    sdk.progressIndicatorEnabled = YES;
    //    4) 是否显示拍摄引导,可以用在第一次使用时，代码如下：
    
    sdk.recordGuideEnabled = YES;
    //    5) 是否开启闪光灯切换,代码如下：
    
    sdk.flashSwitchEnabled = YES;
    //    6) 是否开启美颜切换,代码如下：
    
    sdk.flashSwitchEnabled = YES;
    //    7) 美颜度,可设置的值为0-1，代码如下：
    
    sdk.beautyDegree = 0.8;
    //    8) 主题颜色,设置tintColor属性不能修改sdk中使用到的图片资源。如果有个性化定制需求，请自行替换ALBBQuPaiPlugin.bundle 中对应的图片资源。设置主题颜色代码如下：
    
    sdk.tintColor = [UIColor colorWithRed:100/255.0 green:100/255.0 blue:100/255.0 alpha:1];
    //    9) 底部操作面板高度。默认120，小于85将导致面板显示不全，过大将导致覆盖。顶部操作面板高度44，进度条高度4，可以根据屏幕高度调节bottomPanelHeight使底部面板居中。设置代码如下：
    
    sdk.bottomPanelHeight = 100;
    
    
    
}
//4.录制结束后的代理方法
//取消录制，点击录制界面关闭按钮时触发，示例代码如下：
- (void)qupaiSDKCancel:(QupaiSDK *)sdk{
    [self dismissViewControllerAnimated:YES completion:nil];
}
//内部合成视频，录制完成后，默认触发，示例代码如下：
- (void)qupaiSDK:(QupaiSDK *)sdk compeleteVideoPath:(NSString *)videoPath thumbnailPath:(NSString *)thumbnailPath
{
    NSLog(@"Qupai SDK compelete %@",videoPath);
    [self dismissViewControllerAnimated:YES completion:nil];
    if (videoPath) {
        UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);
    }
    if (thumbnailPath) {
        UIImageWriteToSavedPhotosAlbum([UIImage imageWithContentsOfFile:thumbnailPath], nil, nil, nil);
    }
    [self saveVideo:videoPath thumbnail:thumbnailPath];
    
}

- (void)qupaiSDK:(QupaiSDK *)sdk packName:(NSString *)packName
{
    //    self.packNameLabel.text = packName;
    [self dismissViewControllerAnimated:YES completion:nil];
    
    [[QupaiSDK shared] combinePackName:packName completionBlock:^(NSString *videoPath, NSError *error) {
        UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);
        NSLog(@"Qupai SDK pack compelete %@",videoPath);
    }];
}


//参数说明：
//1.videoPath 保存拍摄好视频的存储路径
//2.thumbnailPath 保存拍摄好视频首侦图的存储路径，如果需要多张图片请调用系统方法获取。
//
//视频信息会在QupaiSDK的videoInfo属性中以字典形式返回，属性值对应的key定义在QupaiSDK.h中，代码如下:
//extern NSString * const QPVideoInfoDuration; // 视频时长 (s)
//extern NSString * const QPVideoInfoLength; // 视频大小 (byte)
//extern NSString * const QPVideoInfoBitRate; // 码率（bps）
//extern NSString * const QPVideoInfoSize; // 分辨率 (pixel*pixel)
#pragma mark - Persistence

- (void) saveVideo:(NSString *)videoPath thumbnail:(NSString *)thumbnailPath {
    // 把视频从临时目录拷贝出来，因为下次录制时会清空临时目录。
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *testDirPath = [documentPath stringByAppendingPathComponent:@"Test"];
    NSFileManager *fileMgr = [NSFileManager defaultManager];
    if (![fileMgr fileExistsAtPath:testDirPath]) {
        [fileMgr createDirectoryAtPath:testDirPath withIntermediateDirectories:NO attributes:nil error:nil];
    }
    NSString *testVideoPath = [testDirPath stringByAppendingPathComponent:[videoPath lastPathComponent]];
    [[NSFileManager defaultManager] copyItemAtPath:videoPath toPath:testVideoPath error:nil];
    
    NSString *testThumbnailPath = [testDirPath stringByAppendingPathComponent:[thumbnailPath lastPathComponent]];
    [[NSFileManager defaultManager] copyItemAtPath:thumbnailPath toPath:testThumbnailPath error:nil];
    
    self.task = [[QPUploadTaskManager shared] createUploadTaskWithVideoPath:testVideoPath thumbnailPath:testThumbnailPath share:0 desc:nil tags:nil];
    self.upLoadButton.hidden = NO;
    [self.upLoadButton setTitle:@"上传" forState:UIControlStateNormal];
    
    
}


#pragma mark 上传按钮
- (void)upLoadButtonAction:(UIButton *)button {
    
    //    七、上传视频功能的使用
    //
    //    上传视频的核心对象是QPUploadTaskManager，他是一个单例对象。用于创建，上传与维护上传任务（QPUploadTask）。QPUploadTask 保存有视频文件路径，上传状态等属性。每创建一个QPUploadTask，QPUploadTaskManager会持久化保存Task对象，并在上传完成后自动删除。
    //
    //    1.创建上传任务
    //
    //    调用QPUploadTaskManager中的创建方法，参数为视频路径与缩略图路径，得到一个QPUploadTask 对象。注意不要手动创建或修改QPUploadTask对象。
    //    请调用如下方法创建QPUploadTask，并将share值（0为公开，1为私有，默认请设为公开，如果设置为公开的视频,获取时不需要accessToken），请各位开发者暂时不要使用demo中的创建方法，请使用以下代码创建，如果不需要tags和desc，可以传nil，示例代码如下：
    
    //    QPUploadTask *uploadTask = [[QPUploadTaskManager shared] createUploadTaskWithVideoPath:videoPath thumbnailPath:thumbnailPath share:0 desc:nil tags:nil];
    
    //    2.上传视频
    //
    //    将得到的QPUploadTask 对象作为参数，调用上传方法。进度的block中可以监控上传的进度，可根据需求设置；成功block中返回视频在服务端存储的remoteId。示例代码如下：
    
    // 看视频  kQPDomain = sdk.s.qupai.me  aglqupai1-0.s.qupai.me
    //    if (uploadTask.uploadFinished) {
    //        NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
    //        NSString *videoString = [NSString stringWithFormat:@"http://%@/v/%@.mp4?token=%@", kQPDomain, uploadTask.remoteId, accessToken];
    //        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:videoString]];
    //
    //        //        NSString *thumbString = [NSString stringWithFormat:@"http:///%@/v/%@.jpg?token=%@", kQPDomain, uploadTask.remoteId, accessToken];
    //        //        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:thumbString]];
    //
    //    }
    
    
    
    
    
    if (self.task.uploadFinished) {
#pragma mark 发布 参数传到bmob

        NSLog(@"remoteId:%@",self.task.remoteId);
        NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
        // 发布上传video地址
        self.streambase = [NSString stringWithFormat:@"http://%@/v/%@.mp4?token=%@", QP_Domain, self.task.remoteId, accessToken];
        // 发布上传图片地址
        self.previewStr = [NSString stringWithFormat:@"http://%@/v/%@.jpg?token=%@", QP_Domain, self.task.remoteId, accessToken];
        
        // 弹出alertView
        [self presentViewController:self.alertView animated:YES completion:^{
            
        }];
        //        [self publishWithPreviewStr:previewStr streambase:streambase];
        
    } else {
#pragma mark 开始上传
        
        [[QPUploadTaskManager shared] startUploadTask:self.task progress:^(CGFloat progress) {
            dispatch_async(dispatch_get_main_queue(), ^{
                self.processView.progress = progress;
                NSLog(@"%f",progress);
            });
        } success:^(QPUploadTask *uploadTask, NSString *remoteId) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"remoteId:%@",remoteId);
                NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
                NSLog(@"得到video地址:http://%@/v/%@.mp4?token=%@",QP_Domain,remoteId, accessToken);
                NSLog(@"得到图片地址:http://%@/v/%@.jpg?token=%@",QP_Domain,remoteId, accessToken);
                [self.upLoadButton setTitle:@"发布" forState:UIControlStateNormal];
                
            });
        } failure:^(NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"upload failed");
            });
        }];
        
        
    }
    
    
    
    
    
    
    
    //    3.断点续传
    //
    //    视频在上传过程中发送意外（如用户杀掉应用，断网，应用Crash等）导致上传没有完成，可以在合适的时机调用getAllUploadTasks方法获取未完成的QPUploadTask列表，QPUploadTask中的progress方法可以获得当前任务的上传进度。调用上传方法完成续传。
    //
    //    4.删除任务
    //
    //    删除单个任务时调用以下方法，先获取任务对象，再调用removeUploadTask方法删除，示例代码如下：
    //    NSArray *tasks = [[QPUploadTaskManager shared] getAllUploadTasks];
    //    [[QPUploadTaskManager shared] removeUploadTask:tasks.firstObject];
    //    删除所有任务调用以下方法，示例代码如下：
    //
    //    [[QPUploadTaskManager shared] removeAllUploadTasks];
    
    //    [self.taskArray removeAllObjects];
    //    [[QPUploadTaskManager shared] removeAllUploadTasks];
    //    [self.tableView reloadData];
    //    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    //    NSString *testDirPath = [documentPath stringByAppendingPathComponent:@"Test"];
    //    NSFileManager *fileMgr = [NSFileManager defaultManager];
    //    [fileMgr removeItemAtPath:testDirPath error:nil];
    
}


-(void)playbackStateChanged{
    
    
    //取得目前状态
    MPMoviePlaybackState playbackState = [_moviePlayer playbackState];
    
    //状态类型
    switch (playbackState) {
        case MPMoviePlaybackStateStopped:
//            [_moviePlayer play];
            NSLog(@"停止");
            break;
            
        case MPMoviePlaybackStatePlaying:
            NSLog(@"播放中");
            break;
            
        case MPMoviePlaybackStatePaused:
//            [_moviePlayer play];
            break;
            
        case MPMoviePlaybackStateInterrupted:
            NSLog(@"播放被中断");
            break;
            
        case MPMoviePlaybackStateSeekingForward:
            NSLog(@"往前快转");
            break;
            
        case MPMoviePlaybackStateSeekingBackward:
            NSLog(@"往后快转");
            break;
            
        default:
            NSLog(@"无法辨识的状态");
            break;
    }
}


- (void)viewWillDisappear:(BOOL)animated {
    [_moviePlayer stop];
}

- (void)viewWillAppear:(BOOL)animated {
    [_moviePlayer play];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
